(* Release 3.10 *)
(*-------------------------------------------------------------------------*
*                                                                          *
*  CPPLOW.A - C++ assembler implementations                                *
*                                                                          *
*  COPYRIGHT (C) 1989..1992 Clarion Software Corporation.                  *
*  All Rights Reserved                                                     *
*                                                                          *
*--------------------------------------------------------------------------*)

include "corelib.inc"

module cpplow

(******************************************************************************)
section

segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
segment _INIT(DATA,28H)

extrn __init_standard

select _TEXT

do_initstandard : (* defined later on ! *)

select _INIT
initio : dw MAGIC
    	 db PRL
         dw do_initstandard

select _DATA
public __assign_init_magic :  dw  0, initio

select  _TEXT

    call __init_standard
    ret  0

(******************************************************************************)
section

segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
segment _INIT(DATA,28H)

extrn __init_con

select _TEXT

do_initcon : (* defined later on ! *)

select _INIT
initcon : dw MAGIC
    	  db PRL
          dw do_initcon

select _DATA
public __flush_init_magic :  dw  0, initcon

select  _TEXT
    call __init_con
    ret  0

(***************************************************************************)
section
segment _DATA(DATA,28H)
segment _TEXT(CODE,28H)

(*
void   _call_ctors(void *(*ctor)(void *), char *obj_ptr, int vbnum, int n, int siz);
void   _call_dtors(void  (*dtor)(void *), char *obj_ptr, int vbnum, int n, int siz);
*)
sframe = 4
tor    = sframe
objptr = 2+sframe
vbnum  = 4+sframe
n      = 6+sframe
siz    = 8+sframe


public __call_ctors :

    push bp
    mov  bp, sp
    push di
    push si
    sub  di, di
ctorsCommon:
    mov  cx, [bp][n]
    jcxz ctDone
ctLoop:
    push cx
    or   di, di
    jz   noDec
    mov  cx, [bp][siz]
    sub  [bp][objptr], cx
noDec:
    mov  si, 3
    mov  ax, [bp][objptr]
    mov  bx, di
    mov  cx, [bp][vbnum]
    mov  dx, di
    sub  cx, si
    jle  ctCallConst
ctPushLoop:
    push dx
    loop ctPushLoop
ctCallConst:
    mov  cx, di
    call word [bp][tor]
    or   di, di
    jnz  noInc
    mov  cx, [bp][siz]
    add  [bp][objptr], cx
noInc:
    pop  cx
    loop ctLoop
ctDone:
    pop  si
    pop  di
    pop  bp
    ret  0

public __call_dtors :

    push bp
    mov  bp, sp
    push di
    push si
    mov  di, 1
    jmp ctorsCommon

(***************************************************************************)
section
segment _TEXT(CODE,28H)

extrn __bcd

public __cvt_bcd :

  xchg ax, bx
  fbld st(0), ss:[bx]
  fstp st(1), st(0)
  xchg ax, bx
  ret  0

public __real_to_dec :

  push bp
  mov  bp, sp
  mov  bx, ax
  fld  st(0), st(0)
  fistp qword [bx], st(0)
  pop  bp
  ret  0

end
